<?php

use Illuminate\Database\Seeder;
use App\Models\Movie;
use App\Models\Category;
use App\Handlers\GetImagesUrlHandler;
use function GuzzleHttp\json_decode;

class MoviesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = app(Faker\Generator::class);
        $nums = 100;
        $movies = factory(Movie::class)->times($nums)->make();

        $top_images = app(GetImagesUrlHandler::class)->get($nums);
        $top_images = json_decode($top_images, true);

        $movies_array = $movies->toArray();

        foreach($movies_array as $k => $movie) {
            $movies_array[$k]['cover'] = $top_images[$k];
        }


        Movie::insert($movies_array);
    }
}
